const STATUS_CODES = {
  SUCCESS: {
    code: 0,
    message: "操作成功",
    httpStatus: 200,
  },
  AUTH_ERROR: {
    code: -1,
    message: "获取登录信息异常，请重新登录",
    httpStatus: 401,
  },
  PARAM_ERROR: {
    code: 400,
    message: "参数错误",
    httpStatus: 400,
  },
  SERVER_ERROR: {
    code: 500,
    message: "服务器内部错误",
    httpStatus: 500,
  },
  NOT_FOUND: {
    code: 404,
    message: "请求的资源不存在",
    httpStatus: 404,
  },
};
const createResponse = (
  res,
  status,
  data = null,
  customMessage = null,
  token = null
) => {
  const { code, message, httpStatus } =
    STATUS_CODES[status] || STATUS_CODES.SERVER_ERROR;
  const response = {
    code,
    message: customMessage || message,
  };
  if (data != null) {
    response.data = data;
  }
  if (token != null) {
    response.token = token;
  }
  return res.status(httpStatus).json(response);
};
module.exports = {
  createResponse,
};
